﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Sol_NetCoreDemo.Controllers.DI;

namespace Sol_NetCoreDemo.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {

        public IConfiguration Configuration { get; }
        public Work2 work2;

        public ValuesController(IConfiguration configuration, Work2 _work2)
        {
            Configuration = configuration;
            work2 = _work2;
        }

        // GET api/values
        [HttpGet]
        public ActionResult<IEnumerable<string>> Get()
        {
            string val1 = work2.World();
            string val2 = Configuration.GetConnectionString("PSQL");
            string val3 = Configuration["section1:key0"];
            string val4 = Configuration["section0:LogLevel:Default"];
            return new string[] { val1, val2, val3, val4 };
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public ActionResult Get(int id)
        {
            return Ok(new { Message = id });
        }

        // POST api/values
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        [HttpGet("InAsyncc")]
        public async Task<IActionResult> InAsyncc()
        {
            var dic = await Task.FromResult(142);
            return Ok(dic);
        }

        [HttpPost("Feach")]
        public IActionResult Feach()
        {
            List<object> users = new List<object>()
            {
                new  { Key = 1,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new  { Key = 2,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new  { Key = 3,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new   { Key = 4,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new   { Key = 5,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new   { Key = 6,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new   { Key = 7,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new   { Key = 8,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new   { Key = 9,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"},
                new   { Key = 10,Name = "胡彦斌", Age = 32,Address="西湖区湖底公园1号"}
            };

            return Ok(users);
        }


    }
}
